// VectorQueue.java
//
// Copyright (C) 2006-2011 University of Seville 
// (Contact Rafael Corchuelo at corchu at us.es)
//
// The only purpose of this file is to be useful to my students.
// Using it for commercial purposes will be prosecuted.

package queues.implementations;

import java.util.Vector;

import queues.exceptions.EmptyQueueException;
import queues.interfaces.IQueue;

/**
 * An implementation of <code>IQueue<T></code> as a vector.
 * 
 * @author Rafael Corchuelo
 */
public class VectorQueue<T> implements IQueue<T> {

	/**
	 * The vector with which the queue is implemented.
	 */
	protected Vector<T> q;

	/**
	 * Constructs a new queue.
	 */
	public VectorQueue() {
		q = new Vector<T>();
	}

	/**
	 * @see queues.interfaces.IQueue#first()
	 */
	public T first() {
		if (q.size() == 0)
			throw new EmptyQueueException();

		return q.get(0);
	}

	/**
	 * @see queues.interfaces.IQueue#append(Object)
	 */
	public void append(T obj) {
		q.add(obj);
	}

	/**
	 * @see queues.interfaces.IQueue#delete()
	 */
	public void delete() {
		if (q.size() == 0)
			throw new EmptyQueueException();

		q.remove(0);
	}

	/**
	 * @see queues.interfaces.IQueue#size()
	 */
	public int size() {
		return q.size();
	}
}
